package gui;

import javax.swing.*;
import java.awt.*;

@FunctionalInterface
interface TaskProcessor<T> {
    void process(T task) throws InterruptedException;
}

// 泛型任务类
class Task<T> {
    private final T data;

    public Task(T data) {
        this.data = data;
    }

    public T getData() {
        return data;
    }
    // 构造函数、getter
}
class aaa {
    static TaskProcessor<String> aa(){
        return task -> {
            System.out.println("a"+task.toUpperCase());
            System.out.println("hello");
        };
    }
}
public class GridBagLayoutExample extends JFrame {
    public GridBagLayoutExample() {
        setTitle("GridBagLayout Glue可见性测试");
        setSize(600, 200);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        JPanel panel = new JPanel(new GridBagLayout());
        add(panel);

        GridBagConstraints gbc = new GridBagConstraints();
        gbc.insets = new Insets(5, 5, 5, 5);

        // 1. 标签（第0列）
        gbc.gridx = 0;
        gbc.gridy = 0;
        gbc.anchor = GridBagConstraints.EAST;
        panel.add(new JLabel("用户名："), gbc);

        // 2. Glue（第1列，红色背景）
        gbc.gridx = 1;
        gbc.weightx = 1.0;
        gbc.fill = GridBagConstraints.HORIZONTAL;
        JComponent glue = (JComponent) Box.createHorizontalGlue();
        glue.setOpaque(true);
        glue.setBackground(Color.RED);
        panel.add(glue, gbc);

        // 3. 输入框（第2列）
        gbc.gridx = 2;
        gbc.weightx = 0; // 输入框列不扩展
        JTextField userField = new JTextField(15);
        panel.add(userField, gbc);

        setVisible(true);
    }

    public static void main(String[] args) {
        new GridBagLayoutExample();
    }
}
